package com.nbjtjc.safe.api.emg.handle;

import cn.hutool.core.util.ObjectUtil;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.emg.handle.EmgHandleGoodsMapper;
import com.nbjtjc.safe.model.emg.handle.EmgHandleGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/emgHandleGoods")
@CrossOrigin("*")
public class EmgHandleGoodsController {
    @Autowired
    private EmgHandleGoodsMapper emgHandleGoodsMapper;
    @SysLog("添加应急处置的物资")
    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    public Result add(@RequestBody EmgHandleGoods emgHandleGoods){
        Result result=new Result();
        if(ObjectUtil.isNull(emgHandleGoods)||ObjectUtil.isNull(emgHandleGoods.getHandleId())){
            result.setFalse("不能为空");
            return result;
        }
        try {
            emgHandleGoodsMapper.insert(emgHandleGoods);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @SysLog("删除应急处置的物资")
    @RequestMapping(value = "/delete",method = {RequestMethod.POST})
    public Result delete(@RequestBody EmgHandleGoods emgHandleGoods){
        Result result=new Result();
        if(ObjectUtil.isNull(emgHandleGoods)||ObjectUtil.isNull(emgHandleGoods.getId())){
            result.setFalse("不能为空");
            return result;
        }
        try {
            emgHandleGoodsMapper.deleteByPrimaryKey(emgHandleGoods);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
